﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!Page.User.Identity.IsAuthenticated)
        //{
        //    Response.Redirect("Login.aspx?ReturnUrl=" + System.Web.HttpUtility.UrlEncode(this.Request.Url.ToString()));
        //    return;
        //}

        string Module = Request.QueryString["mod"];
        string Action = Request.QueryString["page"];
        string SubModule = Request.QueryString["smod"];
        string st = "";
        string url = "";
        if (Module == null) return;
        if (Action == null) return;
        st = Module;
        url = "mod=" + Module;
        if (SubModule != null)
        {
            st = st + "/" + HttpUtility.UrlDecode(SubModule);
            url = url + "&" + "smod=" + HttpUtility.UrlDecode(SubModule);
        }
        st = st + "/" + Action + ".ascx";
        url = url + "&" + "page=" + Action;
        string FullPath = "~/Modules/" + st;
        Control control = null;
        if (System.IO.File.Exists(Server.MapPath(FullPath)))
        {
            control = LoadControl(FullPath);
        }
        else
        {
            FullPath = "~/Modules/" + SubModule + "/" + Action + ".ascx";
            if (System.IO.File.Exists(Server.MapPath(FullPath)))
            {
                control = LoadControl(FullPath);
            }
        }
        if (control != null)
        {
            control.ID = st.Replace(".ascx", "").Replace("/", "_");
            this.ct.Controls.Add(control);
        }
    }
}
